$(function(){
	var t=0;
	if(t==null || t==0){
		var waterflow = $("#waterflow");
		waterflow.masonry({
			itemSelector:'.content-list-water',
			isFitWidth:true
		});
	}else{
		$(".content-list-water").removeClass("content-list-water").addClass("content-list");
	}
	
	windowScroll();
});
function changeWater(isWater){
	if(isWater==0){
		if(location.href.indexOf("?t=1")>0){
			location=location.href.replace("?t=1","");
		}else{
			location = location;
		}
	}else{
		if(location.href.indexOf("?t=1")<0){
			location=location+"?t=1";
		}else{
			location = location;
		}
	}
}

function windowScroll(){
	$(window).scroll(function(){
		if(($(document).height() - $(window).height() - $(document).scrollTop())<10){
			getNewItems();
		}
	});
}

function getNewItems(){
	var typeid = $(":input[name='typeid']");
	var page = $(":input[name='page']");
	var pageSize = $(":input[name='pageSize']");
	
	var hasContent = $(":input[name='hasContent']");
	
	var pageNum = parseInt(page.val())+1;
	if(hasContent.val()==="true"){
		var not_water_flow = $("#not-water-flow");
		$.get("news_finds.jspx",{typeid:typeid.val(),page:pageNum,pageSize:pageSize.val()},function(data){
			page.val(pageNum);
			hasContent.val(data.hasContent);
			var items = data.items;
			if(items!=null){
				/*$.each(items,function(index,element){
					var $this = element;
					var content = "<div class=\"content-list\">"
								  +"     <div class=\"content-title\">"
					              +"       <a href=\"id_"+$this.id+".jspx\">"+$this.title+"</a>"+"<span>"+$this.addtime+"</span>"
					              +"     </div>"
					              +"     <div class=\"content-body\">"
					              +$this.content
					              +"     </div>"
					              +"</div>";
					not_water_flow.append(content);
				});
				*/
				var content = template("news-list-template",{items:items});
				not_water_flow.append(content);
			}
		});
	}
}

